#include "gw-color.h"

typedef struct
{
    const gchar *name;
    GwColor color;
} X11Color;

#define X11_CONST(name, r, g, b) \
    { \
        name, \
        { \
            r / 255.0, g / 255.0, b / 255.0, 1.0 \
        } \
    }

static X11Color X11_COLORS[] = {
    X11_CONST("alice blue", 240, 248, 255),
    X11_CONST("AliceBlue", 240, 248, 255),
    X11_CONST("antique white", 250, 235, 215),
    X11_CONST("AntiqueWhite", 250, 235, 215),
    X11_CONST("AntiqueWhite1", 255, 239, 219),
    X11_CONST("AntiqueWhite2", 238, 223, 204),
    X11_CONST("AntiqueWhite3", 205, 192, 176),
    X11_CONST("AntiqueWhite4", 139, 131, 120),
    X11_CONST("aquamarine", 127, 255, 212),
    X11_CONST("aquamarine1", 127, 255, 212),
    X11_CONST("aquamarine2", 118, 238, 198),
    X11_CONST("aquamarine3", 102, 205, 170),
    X11_CONST("aquamarine4", 69, 139, 116),
    X11_CONST("azure", 240, 255, 255),
    X11_CONST("azure1", 240, 255, 255),
    X11_CONST("azure2", 224, 238, 238),
    X11_CONST("azure3", 193, 205, 205),
    X11_CONST("azure4", 131, 139, 139),
    X11_CONST("beige", 245, 245, 220),
    X11_CONST("bisque", 255, 228, 196),
    X11_CONST("bisque1", 255, 228, 196),
    X11_CONST("bisque2", 238, 213, 183),
    X11_CONST("bisque3", 205, 183, 158),
    X11_CONST("bisque4", 139, 125, 107),
    X11_CONST("black", 0, 0, 0),
    X11_CONST("blanched almond", 255, 235, 205),
    X11_CONST("BlanchedAlmond", 255, 235, 205),
    X11_CONST("blue", 0, 0, 255),
    X11_CONST("blue violet", 138, 43, 226),
    X11_CONST("blue1", 0, 0, 255),
    X11_CONST("blue2", 0, 0, 238),
    X11_CONST("blue3", 0, 0, 205),
    X11_CONST("blue4", 0, 0, 139),
    X11_CONST("BlueViolet", 138, 43, 226),
    X11_CONST("brown", 165, 42, 42),
    X11_CONST("brown1", 255, 64, 64),
    X11_CONST("brown2", 238, 59, 59),
    X11_CONST("brown3", 205, 51, 51),
    X11_CONST("brown4", 139, 35, 35),
    X11_CONST("burlywood", 222, 184, 135),
    X11_CONST("burlywood1", 255, 211, 155),
    X11_CONST("burlywood2", 238, 197, 145),
    X11_CONST("burlywood3", 205, 170, 125),
    X11_CONST("burlywood4", 139, 115, 85),
    X11_CONST("cadet blue", 95, 158, 160),
    X11_CONST("CadetBlue", 95, 158, 160),
    X11_CONST("CadetBlue1", 152, 245, 255),
    X11_CONST("CadetBlue2", 142, 229, 238),
    X11_CONST("CadetBlue3", 122, 197, 205),
    X11_CONST("CadetBlue4", 83, 134, 139),
    X11_CONST("chartreuse", 127, 255, 0),
    X11_CONST("chartreuse1", 127, 255, 0),
    X11_CONST("chartreuse2", 118, 238, 0),
    X11_CONST("chartreuse3", 102, 205, 0),
    X11_CONST("chartreuse4", 69, 139, 0),
    X11_CONST("chocolate", 210, 105, 30),
    X11_CONST("chocolate1", 255, 127, 36),
    X11_CONST("chocolate2", 238, 118, 33),
    X11_CONST("chocolate3", 205, 102, 29),
    X11_CONST("chocolate4", 139, 69, 19),
    X11_CONST("coral", 255, 127, 80),
    X11_CONST("coral1", 255, 114, 86),
    X11_CONST("coral2", 238, 106, 80),
    X11_CONST("coral3", 205, 91, 69),
    X11_CONST("coral4", 139, 62, 47),
    X11_CONST("cornflower blue", 100, 149, 237),
    X11_CONST("CornflowerBlue", 100, 149, 237),
    X11_CONST("cornsilk", 255, 248, 220),
    X11_CONST("cornsilk1", 255, 248, 220),
    X11_CONST("cornsilk2", 238, 232, 205),
    X11_CONST("cornsilk3", 205, 200, 177),
    X11_CONST("cornsilk4", 139, 136, 120),
    X11_CONST("cyan", 0, 255, 255),
    X11_CONST("cyan1", 0, 255, 255),
    X11_CONST("cyan2", 0, 238, 238),
    X11_CONST("cyan3", 0, 205, 205),
    X11_CONST("cyan4", 0, 139, 139),
    X11_CONST("dark blue", 0, 0, 139),
    X11_CONST("dark cyan", 0, 139, 139),
    X11_CONST("dark goldenrod", 184, 134, 11),
    X11_CONST("dark gray", 169, 169, 169),
    X11_CONST("dark green", 0, 100, 0),
    X11_CONST("dark grey", 169, 169, 169),
    X11_CONST("dark khaki", 189, 183, 107),
    X11_CONST("dark magenta", 139, 0, 139),
    X11_CONST("dark olive green", 85, 107, 47),
    X11_CONST("dark orange", 255, 140, 0),
    X11_CONST("dark orchid", 153, 50, 204),
    X11_CONST("dark red", 139, 0, 0),
    X11_CONST("dark salmon", 233, 150, 122),
    X11_CONST("dark sea green", 143, 188, 143),
    X11_CONST("dark slate blue", 72, 61, 139),
    X11_CONST("dark slate gray", 47, 79, 79),
    X11_CONST("dark slate grey", 47, 79, 79),
    X11_CONST("dark turquoise", 0, 206, 209),
    X11_CONST("dark violet", 148, 0, 211),
    X11_CONST("DarkBlue", 0, 0, 139),
    X11_CONST("DarkCyan", 0, 139, 139),
    X11_CONST("DarkGoldenrod", 184, 134, 11),
    X11_CONST("DarkGoldenrod1", 255, 185, 15),
    X11_CONST("DarkGoldenrod2", 238, 173, 14),
    X11_CONST("DarkGoldenrod3", 205, 149, 12),
    X11_CONST("DarkGoldenrod4", 139, 101, 8),
    X11_CONST("DarkGray", 169, 169, 169),
    X11_CONST("DarkGreen", 0, 100, 0),
    X11_CONST("DarkGrey", 169, 169, 169),
    X11_CONST("DarkKhaki", 189, 183, 107),
    X11_CONST("DarkMagenta", 139, 0, 139),
    X11_CONST("DarkOliveGreen", 85, 107, 47),
    X11_CONST("DarkOliveGreen1", 202, 255, 112),
    X11_CONST("DarkOliveGreen2", 188, 238, 104),
    X11_CONST("DarkOliveGreen3", 162, 205, 90),
    X11_CONST("DarkOliveGreen4", 110, 139, 61),
    X11_CONST("DarkOrange", 255, 140, 0),
    X11_CONST("DarkOrange1", 255, 127, 0),
    X11_CONST("DarkOrange2", 238, 118, 0),
    X11_CONST("DarkOrange3", 205, 102, 0),
    X11_CONST("DarkOrange4", 139, 69, 0),
    X11_CONST("DarkOrchid", 153, 50, 204),
    X11_CONST("DarkOrchid1", 191, 62, 255),
    X11_CONST("DarkOrchid2", 178, 58, 238),
    X11_CONST("DarkOrchid3", 154, 50, 205),
    X11_CONST("DarkOrchid4", 104, 34, 139),
    X11_CONST("DarkRed", 139, 0, 0),
    X11_CONST("DarkSalmon", 233, 150, 122),
    X11_CONST("DarkSeaGreen", 143, 188, 143),
    X11_CONST("DarkSeaGreen1", 193, 255, 193),
    X11_CONST("DarkSeaGreen2", 180, 238, 180),
    X11_CONST("DarkSeaGreen3", 155, 205, 155),
    X11_CONST("DarkSeaGreen4", 105, 139, 105),
    X11_CONST("DarkSlateBlue", 72, 61, 139),
    X11_CONST("DarkSlateGray", 47, 79, 79),
    X11_CONST("DarkSlateGray1", 151, 255, 255),
    X11_CONST("DarkSlateGray2", 141, 238, 238),
    X11_CONST("DarkSlateGray3", 121, 205, 205),
    X11_CONST("DarkSlateGray4", 82, 139, 139),
    X11_CONST("DarkSlateGrey", 47, 79, 79),
    X11_CONST("DarkTurquoise", 0, 206, 209),
    X11_CONST("DarkViolet", 148, 0, 211),
    X11_CONST("deep pink", 255, 20, 147),
    X11_CONST("deep sky blue", 0, 191, 255),
    X11_CONST("DeepPink", 255, 20, 147),
    X11_CONST("DeepPink1", 255, 20, 147),
    X11_CONST("DeepPink2", 238, 18, 137),
    X11_CONST("DeepPink3", 205, 16, 118),
    X11_CONST("DeepPink4", 139, 10, 80),
    X11_CONST("DeepSkyBlue", 0, 191, 255),
    X11_CONST("DeepSkyBlue1", 0, 191, 255),
    X11_CONST("DeepSkyBlue2", 0, 178, 238),
    X11_CONST("DeepSkyBlue3", 0, 154, 205),
    X11_CONST("DeepSkyBlue4", 0, 104, 139),
    X11_CONST("dim gray", 105, 105, 105),
    X11_CONST("dim grey", 105, 105, 105),
    X11_CONST("DimGray", 105, 105, 105),
    X11_CONST("DimGrey", 105, 105, 105),
    X11_CONST("dodger blue", 30, 144, 255),
    X11_CONST("DodgerBlue", 30, 144, 255),
    X11_CONST("DodgerBlue1", 30, 144, 255),
    X11_CONST("DodgerBlue2", 28, 134, 238),
    X11_CONST("DodgerBlue3", 24, 116, 205),
    X11_CONST("DodgerBlue4", 16, 78, 139),
    X11_CONST("firebrick", 178, 34, 34),
    X11_CONST("firebrick1", 255, 48, 48),
    X11_CONST("firebrick2", 238, 44, 44),
    X11_CONST("firebrick3", 205, 38, 38),
    X11_CONST("firebrick4", 139, 26, 26),
    X11_CONST("floral white", 255, 250, 240),
    X11_CONST("FloralWhite", 255, 250, 240),
    X11_CONST("forest green", 34, 139, 34),
    X11_CONST("ForestGreen", 34, 139, 34),
    X11_CONST("gainsboro", 220, 220, 220),
    X11_CONST("ghost white", 248, 248, 255),
    X11_CONST("GhostWhite", 248, 248, 255),
    X11_CONST("gold", 255, 215, 0),
    X11_CONST("gold1", 255, 215, 0),
    X11_CONST("gold2", 238, 201, 0),
    X11_CONST("gold3", 205, 173, 0),
    X11_CONST("gold4", 139, 117, 0),
    X11_CONST("goldenrod", 218, 165, 32),
    X11_CONST("goldenrod1", 255, 193, 37),
    X11_CONST("goldenrod2", 238, 180, 34),
    X11_CONST("goldenrod3", 205, 155, 29),
    X11_CONST("goldenrod4", 139, 105, 20),
    X11_CONST("gray", 190, 190, 190),
    X11_CONST("gray0", 0, 0, 0),
    X11_CONST("gray1", 3, 3, 3),
    X11_CONST("gray10", 26, 26, 26),
    X11_CONST("gray100", 255, 255, 255),
    X11_CONST("gray11", 28, 28, 28),
    X11_CONST("gray12", 31, 31, 31),
    X11_CONST("gray13", 33, 33, 33),
    X11_CONST("gray14", 36, 36, 36),
    X11_CONST("gray15", 38, 38, 38),
    X11_CONST("gray16", 41, 41, 41),
    X11_CONST("gray17", 43, 43, 43),
    X11_CONST("gray18", 46, 46, 46),
    X11_CONST("gray19", 48, 48, 48),
    X11_CONST("gray2", 5, 5, 5),
    X11_CONST("gray20", 51, 51, 51),
    X11_CONST("gray21", 54, 54, 54),
    X11_CONST("gray22", 56, 56, 56),
    X11_CONST("gray23", 59, 59, 59),
    X11_CONST("gray24", 61, 61, 61),
    X11_CONST("gray25", 64, 64, 64),
    X11_CONST("gray26", 66, 66, 66),
    X11_CONST("gray27", 69, 69, 69),
    X11_CONST("gray28", 71, 71, 71),
    X11_CONST("gray29", 74, 74, 74),
    X11_CONST("gray3", 8, 8, 8),
    X11_CONST("gray30", 77, 77, 77),
    X11_CONST("gray31", 79, 79, 79),
    X11_CONST("gray32", 82, 82, 82),
    X11_CONST("gray33", 84, 84, 84),
    X11_CONST("gray34", 87, 87, 87),
    X11_CONST("gray35", 89, 89, 89),
    X11_CONST("gray36", 92, 92, 92),
    X11_CONST("gray37", 94, 94, 94),
    X11_CONST("gray38", 97, 97, 97),
    X11_CONST("gray39", 99, 99, 99),
    X11_CONST("gray4", 10, 10, 10),
    X11_CONST("gray40", 102, 102, 102),
    X11_CONST("gray41", 105, 105, 105),
    X11_CONST("gray42", 107, 107, 107),
    X11_CONST("gray43", 110, 110, 110),
    X11_CONST("gray44", 112, 112, 112),
    X11_CONST("gray45", 115, 115, 115),
    X11_CONST("gray46", 117, 117, 117),
    X11_CONST("gray47", 120, 120, 120),
    X11_CONST("gray48", 122, 122, 122),
    X11_CONST("gray49", 125, 125, 125),
    X11_CONST("gray5", 13, 13, 13),
    X11_CONST("gray50", 127, 127, 127),
    X11_CONST("gray51", 130, 130, 130),
    X11_CONST("gray52", 133, 133, 133),
    X11_CONST("gray53", 135, 135, 135),
    X11_CONST("gray54", 138, 138, 138),
    X11_CONST("gray55", 140, 140, 140),
    X11_CONST("gray56", 143, 143, 143),
    X11_CONST("gray57", 145, 145, 145),
    X11_CONST("gray58", 148, 148, 148),
    X11_CONST("gray59", 150, 150, 150),
    X11_CONST("gray6", 15, 15, 15),
    X11_CONST("gray60", 153, 153, 153),
    X11_CONST("gray61", 156, 156, 156),
    X11_CONST("gray62", 158, 158, 158),
    X11_CONST("gray63", 161, 161, 161),
    X11_CONST("gray64", 163, 163, 163),
    X11_CONST("gray65", 166, 166, 166),
    X11_CONST("gray66", 168, 168, 168),
    X11_CONST("gray67", 171, 171, 171),
    X11_CONST("gray68", 173, 173, 173),
    X11_CONST("gray69", 176, 176, 176),
    X11_CONST("gray7", 18, 18, 18),
    X11_CONST("gray70", 179, 179, 179),
    X11_CONST("gray71", 181, 181, 181),
    X11_CONST("gray72", 184, 184, 184),
    X11_CONST("gray73", 186, 186, 186),
    X11_CONST("gray74", 189, 189, 189),
    X11_CONST("gray75", 191, 191, 191),
    X11_CONST("gray76", 194, 194, 194),
    X11_CONST("gray77", 196, 196, 196),
    X11_CONST("gray78", 199, 199, 199),
    X11_CONST("gray79", 201, 201, 201),
    X11_CONST("gray8", 20, 20, 20),
    X11_CONST("gray80", 204, 204, 204),
    X11_CONST("gray81", 207, 207, 207),
    X11_CONST("gray82", 209, 209, 209),
    X11_CONST("gray83", 212, 212, 212),
    X11_CONST("gray84", 214, 214, 214),
    X11_CONST("gray85", 217, 217, 217),
    X11_CONST("gray86", 219, 219, 219),
    X11_CONST("gray87", 222, 222, 222),
    X11_CONST("gray88", 224, 224, 224),
    X11_CONST("gray89", 227, 227, 227),
    X11_CONST("gray9", 23, 23, 23),
    X11_CONST("gray90", 229, 229, 229),
    X11_CONST("gray91", 232, 232, 232),
    X11_CONST("gray92", 235, 235, 235),
    X11_CONST("gray93", 237, 237, 237),
    X11_CONST("gray94", 240, 240, 240),
    X11_CONST("gray95", 242, 242, 242),
    X11_CONST("gray96", 245, 245, 245),
    X11_CONST("gray97", 247, 247, 247),
    X11_CONST("gray98", 250, 250, 250),
    X11_CONST("gray99", 252, 252, 252),
    X11_CONST("green", 0, 255, 0),
    X11_CONST("green yellow", 173, 255, 47),
    X11_CONST("green1", 0, 255, 0),
    X11_CONST("green2", 0, 238, 0),
    X11_CONST("green3", 0, 205, 0),
    X11_CONST("green4", 0, 139, 0),
    X11_CONST("GreenYellow", 173, 255, 47),
    X11_CONST("grey", 190, 190, 190),
    X11_CONST("grey0", 0, 0, 0),
    X11_CONST("grey1", 3, 3, 3),
    X11_CONST("grey10", 26, 26, 26),
    X11_CONST("grey100", 255, 255, 255),
    X11_CONST("grey11", 28, 28, 28),
    X11_CONST("grey12", 31, 31, 31),
    X11_CONST("grey13", 33, 33, 33),
    X11_CONST("grey14", 36, 36, 36),
    X11_CONST("grey15", 38, 38, 38),
    X11_CONST("grey16", 41, 41, 41),
    X11_CONST("grey17", 43, 43, 43),
    X11_CONST("grey18", 46, 46, 46),
    X11_CONST("grey19", 48, 48, 48),
    X11_CONST("grey2", 5, 5, 5),
    X11_CONST("grey20", 51, 51, 51),
    X11_CONST("grey21", 54, 54, 54),
    X11_CONST("grey22", 56, 56, 56),
    X11_CONST("grey23", 59, 59, 59),
    X11_CONST("grey24", 61, 61, 61),
    X11_CONST("grey25", 64, 64, 64),
    X11_CONST("grey26", 66, 66, 66),
    X11_CONST("grey27", 69, 69, 69),
    X11_CONST("grey28", 71, 71, 71),
    X11_CONST("grey29", 74, 74, 74),
    X11_CONST("grey3", 8, 8, 8),
    X11_CONST("grey30", 77, 77, 77),
    X11_CONST("grey31", 79, 79, 79),
    X11_CONST("grey32", 82, 82, 82),
    X11_CONST("grey33", 84, 84, 84),
    X11_CONST("grey34", 87, 87, 87),
    X11_CONST("grey35", 89, 89, 89),
    X11_CONST("grey36", 92, 92, 92),
    X11_CONST("grey37", 94, 94, 94),
    X11_CONST("grey38", 97, 97, 97),
    X11_CONST("grey39", 99, 99, 99),
    X11_CONST("grey4", 10, 10, 10),
    X11_CONST("grey40", 102, 102, 102),
    X11_CONST("grey41", 105, 105, 105),
    X11_CONST("grey42", 107, 107, 107),
    X11_CONST("grey43", 110, 110, 110),
    X11_CONST("grey44", 112, 112, 112),
    X11_CONST("grey45", 115, 115, 115),
    X11_CONST("grey46", 117, 117, 117),
    X11_CONST("grey47", 120, 120, 120),
    X11_CONST("grey48", 122, 122, 122),
    X11_CONST("grey49", 125, 125, 125),
    X11_CONST("grey5", 13, 13, 13),
    X11_CONST("grey50", 127, 127, 127),
    X11_CONST("grey51", 130, 130, 130),
    X11_CONST("grey52", 133, 133, 133),
    X11_CONST("grey53", 135, 135, 135),
    X11_CONST("grey54", 138, 138, 138),
    X11_CONST("grey55", 140, 140, 140),
    X11_CONST("grey56", 143, 143, 143),
    X11_CONST("grey57", 145, 145, 145),
    X11_CONST("grey58", 148, 148, 148),
    X11_CONST("grey59", 150, 150, 150),
    X11_CONST("grey6", 15, 15, 15),
    X11_CONST("grey60", 153, 153, 153),
    X11_CONST("grey61", 156, 156, 156),
    X11_CONST("grey62", 158, 158, 158),
    X11_CONST("grey63", 161, 161, 161),
    X11_CONST("grey64", 163, 163, 163),
    X11_CONST("grey65", 166, 166, 166),
    X11_CONST("grey66", 168, 168, 168),
    X11_CONST("grey67", 171, 171, 171),
    X11_CONST("grey68", 173, 173, 173),
    X11_CONST("grey69", 176, 176, 176),
    X11_CONST("grey7", 18, 18, 18),
    X11_CONST("grey70", 179, 179, 179),
    X11_CONST("grey71", 181, 181, 181),
    X11_CONST("grey72", 184, 184, 184),
    X11_CONST("grey73", 186, 186, 186),
    X11_CONST("grey74", 189, 189, 189),
    X11_CONST("grey75", 191, 191, 191),
    X11_CONST("grey76", 194, 194, 194),
    X11_CONST("grey77", 196, 196, 196),
    X11_CONST("grey78", 199, 199, 199),
    X11_CONST("grey79", 201, 201, 201),
    X11_CONST("grey8", 20, 20, 20),
    X11_CONST("grey80", 204, 204, 204),
    X11_CONST("grey81", 207, 207, 207),
    X11_CONST("grey82", 209, 209, 209),
    X11_CONST("grey83", 212, 212, 212),
    X11_CONST("grey84", 214, 214, 214),
    X11_CONST("grey85", 217, 217, 217),
    X11_CONST("grey86", 219, 219, 219),
    X11_CONST("grey87", 222, 222, 222),
    X11_CONST("grey88", 224, 224, 224),
    X11_CONST("grey89", 227, 227, 227),
    X11_CONST("grey9", 23, 23, 23),
    X11_CONST("grey90", 229, 229, 229),
    X11_CONST("grey91", 232, 232, 232),
    X11_CONST("grey92", 235, 235, 235),
    X11_CONST("grey93", 237, 237, 237),
    X11_CONST("grey94", 240, 240, 240),
    X11_CONST("grey95", 242, 242, 242),
    X11_CONST("grey96", 245, 245, 245),
    X11_CONST("grey97", 247, 247, 247),
    X11_CONST("grey98", 250, 250, 250),
    X11_CONST("grey99", 252, 252, 252),
    X11_CONST("honeydew", 240, 255, 240),
    X11_CONST("honeydew1", 240, 255, 240),
    X11_CONST("honeydew2", 224, 238, 224),
    X11_CONST("honeydew3", 193, 205, 193),
    X11_CONST("honeydew4", 131, 139, 131),
    X11_CONST("hot pink", 255, 105, 180),
    X11_CONST("HotPink", 255, 105, 180),
    X11_CONST("HotPink1", 255, 110, 180),
    X11_CONST("HotPink2", 238, 106, 167),
    X11_CONST("HotPink3", 205, 96, 144),
    X11_CONST("HotPink4", 139, 58, 98),
    X11_CONST("indian red", 205, 92, 92),
    X11_CONST("IndianRed", 205, 92, 92),
    X11_CONST("IndianRed1", 255, 106, 106),
    X11_CONST("IndianRed2", 238, 99, 99),
    X11_CONST("IndianRed3", 205, 85, 85),
    X11_CONST("IndianRed4", 139, 58, 58),
    X11_CONST("ivory", 255, 255, 240),
    X11_CONST("ivory1", 255, 255, 240),
    X11_CONST("ivory2", 238, 238, 224),
    X11_CONST("ivory3", 205, 205, 193),
    X11_CONST("ivory4", 139, 139, 131),
    X11_CONST("khaki", 240, 230, 140),
    X11_CONST("khaki1", 255, 246, 143),
    X11_CONST("khaki2", 238, 230, 133),
    X11_CONST("khaki3", 205, 198, 115),
    X11_CONST("khaki4", 139, 134, 78),
    X11_CONST("lavender", 230, 230, 250),
    X11_CONST("lavender blush", 255, 240, 245),
    X11_CONST("LavenderBlush", 255, 240, 245),
    X11_CONST("LavenderBlush1", 255, 240, 245),
    X11_CONST("LavenderBlush2", 238, 224, 229),
    X11_CONST("LavenderBlush3", 205, 193, 197),
    X11_CONST("LavenderBlush4", 139, 131, 134),
    X11_CONST("lawn green", 124, 252, 0),
    X11_CONST("LawnGreen", 124, 252, 0),
    X11_CONST("lemon chiffon", 255, 250, 205),
    X11_CONST("LemonChiffon", 255, 250, 205),
    X11_CONST("LemonChiffon1", 255, 250, 205),
    X11_CONST("LemonChiffon2", 238, 233, 191),
    X11_CONST("LemonChiffon3", 205, 201, 165),
    X11_CONST("LemonChiffon4", 139, 137, 112),
    X11_CONST("light blue", 173, 216, 230),
    X11_CONST("light coral", 240, 128, 128),
    X11_CONST("light cyan", 224, 255, 255),
    X11_CONST("light goldenrod", 238, 221, 130),
    X11_CONST("light goldenrod yellow", 250, 250, 210),
    X11_CONST("light gray", 211, 211, 211),
    X11_CONST("light green", 144, 238, 144),
    X11_CONST("light grey", 211, 211, 211),
    X11_CONST("light pink", 255, 182, 193),
    X11_CONST("light salmon", 255, 160, 122),
    X11_CONST("light sea green", 32, 178, 170),
    X11_CONST("light sky blue", 135, 206, 250),
    X11_CONST("light slate blue", 132, 112, 255),
    X11_CONST("light slate gray", 119, 136, 153),
    X11_CONST("light slate grey", 119, 136, 153),
    X11_CONST("light steel blue", 176, 196, 222),
    X11_CONST("light yellow", 255, 255, 224),
    X11_CONST("LightBlue", 173, 216, 230),
    X11_CONST("LightBlue1", 191, 239, 255),
    X11_CONST("LightBlue2", 178, 223, 238),
    X11_CONST("LightBlue3", 154, 192, 205),
    X11_CONST("LightBlue4", 104, 131, 139),
    X11_CONST("LightCoral", 240, 128, 128),
    X11_CONST("LightCyan", 224, 255, 255),
    X11_CONST("LightCyan1", 224, 255, 255),
    X11_CONST("LightCyan2", 209, 238, 238),
    X11_CONST("LightCyan3", 180, 205, 205),
    X11_CONST("LightCyan4", 122, 139, 139),
    X11_CONST("LightGoldenrod", 238, 221, 130),
    X11_CONST("LightGoldenrod1", 255, 236, 139),
    X11_CONST("LightGoldenrod2", 238, 220, 130),
    X11_CONST("LightGoldenrod3", 205, 190, 112),
    X11_CONST("LightGoldenrod4", 139, 129, 76),
    X11_CONST("LightGoldenrodYellow", 250, 250, 210),
    X11_CONST("LightGray", 211, 211, 211),
    X11_CONST("LightGreen", 144, 238, 144),
    X11_CONST("LightGrey", 211, 211, 211),
    X11_CONST("LightPink", 255, 182, 193),
    X11_CONST("LightPink1", 255, 174, 185),
    X11_CONST("LightPink2", 238, 162, 173),
    X11_CONST("LightPink3", 205, 140, 149),
    X11_CONST("LightPink4", 139, 95, 101),
    X11_CONST("LightSalmon", 255, 160, 122),
    X11_CONST("LightSalmon1", 255, 160, 122),
    X11_CONST("LightSalmon2", 238, 149, 114),
    X11_CONST("LightSalmon3", 205, 129, 98),
    X11_CONST("LightSalmon4", 139, 87, 66),
    X11_CONST("LightSeaGreen", 32, 178, 170),
    X11_CONST("LightSkyBlue", 135, 206, 250),
    X11_CONST("LightSkyBlue1", 176, 226, 255),
    X11_CONST("LightSkyBlue2", 164, 211, 238),
    X11_CONST("LightSkyBlue3", 141, 182, 205),
    X11_CONST("LightSkyBlue4", 96, 123, 139),
    X11_CONST("LightSlateBlue", 132, 112, 255),
    X11_CONST("LightSlateGray", 119, 136, 153),
    X11_CONST("LightSlateGrey", 119, 136, 153),
    X11_CONST("LightSteelBlue", 176, 196, 222),
    X11_CONST("LightSteelBlue1", 202, 225, 255),
    X11_CONST("LightSteelBlue2", 188, 210, 238),
    X11_CONST("LightSteelBlue3", 162, 181, 205),
    X11_CONST("LightSteelBlue4", 110, 123, 139),
    X11_CONST("LightYellow", 255, 255, 224),
    X11_CONST("LightYellow1", 255, 255, 224),
    X11_CONST("LightYellow2", 238, 238, 209),
    X11_CONST("LightYellow3", 205, 205, 180),
    X11_CONST("LightYellow4", 139, 139, 122),
    X11_CONST("lime green", 50, 205, 50),
    X11_CONST("LimeGreen", 50, 205, 50),
    X11_CONST("linen", 250, 240, 230),
    X11_CONST("magenta", 255, 0, 255),
    X11_CONST("magenta1", 255, 0, 255),
    X11_CONST("magenta2", 238, 0, 238),
    X11_CONST("magenta3", 205, 0, 205),
    X11_CONST("magenta4", 139, 0, 139),
    X11_CONST("maroon", 176, 48, 96),
    X11_CONST("maroon1", 255, 52, 179),
    X11_CONST("maroon2", 238, 48, 167),
    X11_CONST("maroon3", 205, 41, 144),
    X11_CONST("maroon4", 139, 28, 98),
    X11_CONST("medium aquamarine", 102, 205, 170),
    X11_CONST("medium blue", 0, 0, 205),
    X11_CONST("medium orchid", 186, 85, 211),
    X11_CONST("medium purple", 147, 112, 219),
    X11_CONST("medium sea green", 60, 179, 113),
    X11_CONST("medium slate blue", 123, 104, 238),
    X11_CONST("medium spring green", 0, 250, 154),
    X11_CONST("medium turquoise", 72, 209, 204),
    X11_CONST("medium violet red", 199, 21, 133),
    X11_CONST("MediumAquamarine", 102, 205, 170),
    X11_CONST("MediumBlue", 0, 0, 205),
    X11_CONST("MediumOrchid", 186, 85, 211),
    X11_CONST("MediumOrchid1", 224, 102, 255),
    X11_CONST("MediumOrchid2", 209, 95, 238),
    X11_CONST("MediumOrchid3", 180, 82, 205),
    X11_CONST("MediumOrchid4", 122, 55, 139),
    X11_CONST("MediumPurple", 147, 112, 219),
    X11_CONST("MediumPurple1", 171, 130, 255),
    X11_CONST("MediumPurple2", 159, 121, 238),
    X11_CONST("MediumPurple3", 137, 104, 205),
    X11_CONST("MediumPurple4", 93, 71, 139),
    X11_CONST("MediumSeaGreen", 60, 179, 113),
    X11_CONST("MediumSlateBlue", 123, 104, 238),
    X11_CONST("MediumSpringGreen", 0, 250, 154),
    X11_CONST("MediumTurquoise", 72, 209, 204),
    X11_CONST("MediumVioletRed", 199, 21, 133),
    X11_CONST("midnight blue", 25, 25, 112),
    X11_CONST("MidnightBlue", 25, 25, 112),
    X11_CONST("mint cream", 245, 255, 250),
    X11_CONST("MintCream", 245, 255, 250),
    X11_CONST("misty rose", 255, 228, 225),
    X11_CONST("MistyRose", 255, 228, 225),
    X11_CONST("MistyRose1", 255, 228, 225),
    X11_CONST("MistyRose2", 238, 213, 210),
    X11_CONST("MistyRose3", 205, 183, 181),
    X11_CONST("MistyRose4", 139, 125, 123),
    X11_CONST("moccasin", 255, 228, 181),
    X11_CONST("navajo white", 255, 222, 173),
    X11_CONST("NavajoWhite", 255, 222, 173),
    X11_CONST("NavajoWhite1", 255, 222, 173),
    X11_CONST("NavajoWhite2", 238, 207, 161),
    X11_CONST("NavajoWhite3", 205, 179, 139),
    X11_CONST("NavajoWhite4", 139, 121, 94),
    X11_CONST("navy", 0, 0, 128),
    X11_CONST("navy blue", 0, 0, 128),
    X11_CONST("NavyBlue", 0, 0, 128),
    X11_CONST("old lace", 253, 245, 230),
    X11_CONST("OldLace", 253, 245, 230),
    X11_CONST("olive drab", 107, 142, 35),
    X11_CONST("OliveDrab", 107, 142, 35),
    X11_CONST("OliveDrab1", 192, 255, 62),
    X11_CONST("OliveDrab2", 179, 238, 58),
    X11_CONST("OliveDrab3", 154, 205, 50),
    X11_CONST("OliveDrab4", 105, 139, 34),
    X11_CONST("orange", 255, 165, 0),
    X11_CONST("orange red", 255, 69, 0),
    X11_CONST("orange1", 255, 165, 0),
    X11_CONST("orange2", 238, 154, 0),
    X11_CONST("orange3", 205, 133, 0),
    X11_CONST("orange4", 139, 90, 0),
    X11_CONST("OrangeRed", 255, 69, 0),
    X11_CONST("OrangeRed1", 255, 69, 0),
    X11_CONST("OrangeRed2", 238, 64, 0),
    X11_CONST("OrangeRed3", 205, 55, 0),
    X11_CONST("OrangeRed4", 139, 37, 0),
    X11_CONST("orchid", 218, 112, 214),
    X11_CONST("orchid1", 255, 131, 250),
    X11_CONST("orchid2", 238, 122, 233),
    X11_CONST("orchid3", 205, 105, 201),
    X11_CONST("orchid4", 139, 71, 137),
    X11_CONST("pale goldenrod", 238, 232, 170),
    X11_CONST("pale green", 152, 251, 152),
    X11_CONST("pale turquoise", 175, 238, 238),
    X11_CONST("pale violet red", 219, 112, 147),
    X11_CONST("PaleGoldenrod", 238, 232, 170),
    X11_CONST("PaleGreen", 152, 251, 152),
    X11_CONST("PaleGreen1", 154, 255, 154),
    X11_CONST("PaleGreen2", 144, 238, 144),
    X11_CONST("PaleGreen3", 124, 205, 124),
    X11_CONST("PaleGreen4", 84, 139, 84),
    X11_CONST("PaleTurquoise", 175, 238, 238),
    X11_CONST("PaleTurquoise1", 187, 255, 255),
    X11_CONST("PaleTurquoise2", 174, 238, 238),
    X11_CONST("PaleTurquoise3", 150, 205, 205),
    X11_CONST("PaleTurquoise4", 102, 139, 139),
    X11_CONST("PaleVioletRed", 219, 112, 147),
    X11_CONST("PaleVioletRed1", 255, 130, 171),
    X11_CONST("PaleVioletRed2", 238, 121, 159),
    X11_CONST("PaleVioletRed3", 205, 104, 137),
    X11_CONST("PaleVioletRed4", 139, 71, 93),
    X11_CONST("papaya whip", 255, 239, 213),
    X11_CONST("PapayaWhip", 255, 239, 213),
    X11_CONST("peach puff", 255, 218, 185),
    X11_CONST("PeachPuff", 255, 218, 185),
    X11_CONST("PeachPuff1", 255, 218, 185),
    X11_CONST("PeachPuff2", 238, 203, 173),
    X11_CONST("PeachPuff3", 205, 175, 149),
    X11_CONST("PeachPuff4", 139, 119, 101),
    X11_CONST("peru", 205, 133, 63),
    X11_CONST("pink", 255, 192, 203),
    X11_CONST("pink1", 255, 181, 197),
    X11_CONST("pink2", 238, 169, 184),
    X11_CONST("pink3", 205, 145, 158),
    X11_CONST("pink4", 139, 99, 108),
    X11_CONST("plum", 221, 160, 221),
    X11_CONST("plum1", 255, 187, 255),
    X11_CONST("plum2", 238, 174, 238),
    X11_CONST("plum3", 205, 150, 205),
    X11_CONST("plum4", 139, 102, 139),
    X11_CONST("powder blue", 176, 224, 230),
    X11_CONST("PowderBlue", 176, 224, 230),
    X11_CONST("purple", 160, 32, 240),
    X11_CONST("purple1", 155, 48, 255),
    X11_CONST("purple2", 145, 44, 238),
    X11_CONST("purple3", 125, 38, 205),
    X11_CONST("purple4", 85, 26, 139),
    X11_CONST("red", 255, 0, 0),
    X11_CONST("red1", 255, 0, 0),
    X11_CONST("red2", 238, 0, 0),
    X11_CONST("red3", 205, 0, 0),
    X11_CONST("red4", 139, 0, 0),
    X11_CONST("rosy brown", 188, 143, 143),
    X11_CONST("RosyBrown", 188, 143, 143),
    X11_CONST("RosyBrown1", 255, 193, 193),
    X11_CONST("RosyBrown2", 238, 180, 180),
    X11_CONST("RosyBrown3", 205, 155, 155),
    X11_CONST("RosyBrown4", 139, 105, 105),
    X11_CONST("royal blue", 65, 105, 225),
    X11_CONST("RoyalBlue", 65, 105, 225),
    X11_CONST("RoyalBlue1", 72, 118, 255),
    X11_CONST("RoyalBlue2", 67, 110, 238),
    X11_CONST("RoyalBlue3", 58, 95, 205),
    X11_CONST("RoyalBlue4", 39, 64, 139),
    X11_CONST("saddle brown", 139, 69, 19),
    X11_CONST("SaddleBrown", 139, 69, 19),
    X11_CONST("salmon", 250, 128, 114),
    X11_CONST("salmon1", 255, 140, 105),
    X11_CONST("salmon2", 238, 130, 98),
    X11_CONST("salmon3", 205, 112, 84),
    X11_CONST("salmon4", 139, 76, 57),
    X11_CONST("sandy brown", 244, 164, 96),
    X11_CONST("SandyBrown", 244, 164, 96),
    X11_CONST("sea green", 46, 139, 87),
    X11_CONST("SeaGreen", 46, 139, 87),
    X11_CONST("SeaGreen1", 84, 255, 159),
    X11_CONST("SeaGreen2", 78, 238, 148),
    X11_CONST("SeaGreen3", 67, 205, 128),
    X11_CONST("SeaGreen4", 46, 139, 87),
    X11_CONST("seashell", 255, 245, 238),
    X11_CONST("seashell1", 255, 245, 238),
    X11_CONST("seashell2", 238, 229, 222),
    X11_CONST("seashell3", 205, 197, 191),
    X11_CONST("seashell4", 139, 134, 130),
    X11_CONST("sienna", 160, 82, 45),
    X11_CONST("sienna1", 255, 130, 71),
    X11_CONST("sienna2", 238, 121, 66),
    X11_CONST("sienna3", 205, 104, 57),
    X11_CONST("sienna4", 139, 71, 38),
    X11_CONST("sky blue", 135, 206, 235),
    X11_CONST("SkyBlue", 135, 206, 235),
    X11_CONST("SkyBlue1", 135, 206, 255),
    X11_CONST("SkyBlue2", 126, 192, 238),
    X11_CONST("SkyBlue3", 108, 166, 205),
    X11_CONST("SkyBlue4", 74, 112, 139),
    X11_CONST("slate blue", 106, 90, 205),
    X11_CONST("slate gray", 112, 128, 144),
    X11_CONST("slate grey", 112, 128, 144),
    X11_CONST("SlateBlue", 106, 90, 205),
    X11_CONST("SlateBlue1", 131, 111, 255),
    X11_CONST("SlateBlue2", 122, 103, 238),
    X11_CONST("SlateBlue3", 105, 89, 205),
    X11_CONST("SlateBlue4", 71, 60, 139),
    X11_CONST("SlateGray", 112, 128, 144),
    X11_CONST("SlateGray1", 198, 226, 255),
    X11_CONST("SlateGray2", 185, 211, 238),
    X11_CONST("SlateGray3", 159, 182, 205),
    X11_CONST("SlateGray4", 108, 123, 139),
    X11_CONST("SlateGrey", 112, 128, 144),
    X11_CONST("snow", 255, 250, 250),
    X11_CONST("snow1", 255, 250, 250),
    X11_CONST("snow2", 238, 233, 233),
    X11_CONST("snow3", 205, 201, 201),
    X11_CONST("snow4", 139, 137, 137),
    X11_CONST("spring green", 0, 255, 127),
    X11_CONST("SpringGreen", 0, 255, 127),
    X11_CONST("SpringGreen1", 0, 255, 127),
    X11_CONST("SpringGreen2", 0, 238, 118),
    X11_CONST("SpringGreen3", 0, 205, 102),
    X11_CONST("SpringGreen4", 0, 139, 69),
    X11_CONST("steel blue", 70, 130, 180),
    X11_CONST("SteelBlue", 70, 130, 180),
    X11_CONST("SteelBlue1", 99, 184, 255),
    X11_CONST("SteelBlue2", 92, 172, 238),
    X11_CONST("SteelBlue3", 79, 148, 205),
    X11_CONST("SteelBlue4", 54, 100, 139),
    X11_CONST("tan", 210, 180, 140),
    X11_CONST("tan1", 255, 165, 79),
    X11_CONST("tan2", 238, 154, 73),
    X11_CONST("tan3", 205, 133, 63),
    X11_CONST("tan4", 139, 90, 43),
    X11_CONST("thistle", 216, 191, 216),
    X11_CONST("thistle1", 255, 225, 255),
    X11_CONST("thistle2", 238, 210, 238),
    X11_CONST("thistle3", 205, 181, 205),
    X11_CONST("thistle4", 139, 123, 139),
    X11_CONST("tomato", 255, 99, 71),
    X11_CONST("tomato1", 255, 99, 71),
    X11_CONST("tomato2", 238, 92, 66),
    X11_CONST("tomato3", 205, 79, 57),
    X11_CONST("tomato4", 139, 54, 38),
    X11_CONST("turquoise", 64, 224, 208),
    X11_CONST("turquoise1", 0, 245, 255),
    X11_CONST("turquoise2", 0, 229, 238),
    X11_CONST("turquoise3", 0, 197, 205),
    X11_CONST("turquoise4", 0, 134, 139),
    X11_CONST("violet", 238, 130, 238),
    X11_CONST("violet red", 208, 32, 144),
    X11_CONST("VioletRed", 208, 32, 144),
    X11_CONST("VioletRed1", 255, 62, 150),
    X11_CONST("VioletRed2", 238, 58, 140),
    X11_CONST("VioletRed3", 205, 50, 120),
    X11_CONST("VioletRed4", 139, 34, 82),
    X11_CONST("wheat", 245, 222, 179),
    X11_CONST("wheat1", 255, 231, 186),
    X11_CONST("wheat2", 238, 216, 174),
    X11_CONST("wheat3", 205, 186, 150),
    X11_CONST("wheat4", 139, 126, 102),
    X11_CONST("white", 255, 255, 255),
    X11_CONST("white smoke", 245, 245, 245),
    X11_CONST("WhiteSmoke", 245, 245, 245),
    X11_CONST("yellow", 255, 255, 0),
    X11_CONST("yellow green", 154, 205, 50),
    X11_CONST("yellow1", 255, 255, 0),
    X11_CONST("yellow2", 238, 238, 0),
    X11_CONST("yellow3", 205, 205, 0),
    X11_CONST("yellow4", 139, 139, 0),
    X11_CONST("YellowGreen", 154, 205, 50),
};

static int compare_x11_color(const void *a, const void *b)
{
    const gchar *key = a;
    const X11Color *color = b;

    return g_ascii_strcasecmp(key, color->name);
}

static GwColor *gw_color_copy(GwColor *color)
{
    GwColor *copy = g_new(GwColor, 1);
    *copy = *color;

    return copy;
}

G_DEFINE_BOXED_TYPE(GwColor, gw_color, gw_color_copy, g_free)

const GwColor GW_COLOR_BLACK = {0.0, 0.0, 0.0, 1.0};
const GwColor GW_COLOR_WHITE = {1.0, 1.0, 1.0, 1.0};

/**
 * gw_color_equal:
 * @a: The first #GwColor.
 * @b: The second #GwColor.
 *
 * Compares two colors.
 *
 * Returns: %TRUE if the colors are equal.
 */
gboolean gw_color_equal(gconstpointer a, gconstpointer b)
{
    g_return_val_if_fail(a != NULL, FALSE);
    g_return_val_if_fail(b != NULL, FALSE);

    const GwColor *color_a = a;
    const GwColor *color_b = b;

    return color_a->r == color_b->r && color_a->g == color_b->g && color_a->b == color_b->b &&
           color_a->a == color_b->a;
}

/**
 * gw_color_init_from_x11_name:
 * @self: The #GwColor to initialize.
 * @color_name: The X11 color name.
 *
 * Initializes a #GwColor from a X11 color name.
 *
 * Returns: %TRUE if the name was valid.
 */
gboolean gw_color_init_from_x11_name(GwColor *self, const gchar *color_name)
{
    g_return_val_if_fail(self != NULL, FALSE);
    g_return_val_if_fail(color_name != NULL, FALSE);

    X11Color *x11_color = bsearch(color_name,
                                  X11_COLORS,
                                  G_N_ELEMENTS(X11_COLORS),
                                  sizeof(X11Color),
                                  compare_x11_color);
    if (x11_color == NULL) {
        return FALSE;
    }

    *self = x11_color->color;
    return TRUE;
}

/**
 * gw_color_init_from_hex:
 * @self: The #GwColor to initialize.
 * @hex: The hex color.
 *
 * Initializes a #GwColor from a hex color.
 *
 * Returns: %TRUE if the hex color was valid.
 */
gboolean gw_color_init_from_hex(GwColor *self, const gchar *hex)
{
    g_return_val_if_fail(self != NULL, FALSE);
    g_return_val_if_fail(hex != NULL, FALSE);

    if (strnlen(hex, 7) != 6) {
        return FALSE;
    }

    gchar *end = NULL;
    guint64 value = g_ascii_strtoull(hex, &end, 16);
    if (*end != '\0') {
        return FALSE;
    }

    self->r = ((value >> 16) & 0xFF) / 255.0;
    self->g = ((value >> 8) & 0xFF) / 255.0;
    self->b = ((value >> 0) & 0xFF) / 255.0;
    self->a = 1.0;

    return TRUE;
}

/**
 * gw_color_to_hex:
 * @self: A #GwColor.
 *
 * Converts a color into a hex string.
 *
 * Returns: A string in the form "#RRGGBBAA".
 */
gchar *gw_color_to_hex(const GwColor *self)
{
    gint r = CLAMP(self->r, 0.0, 1.0) * 255.0;
    gint g = CLAMP(self->g, 0.0, 1.0) * 255.0;
    gint b = CLAMP(self->b, 0.0, 1.0) * 255.0;
    gint a = CLAMP(self->a, 0.0, 1.0) * 255.0;

    return g_strdup_printf("#%02X%02X%02X%02X", r, g, b, a);
}

const GwColor *gw_rainbow_color_to_color(GwRainbowColor self)
{
    g_return_val_if_fail(self >= 0 && self < GW_NUM_RAINBOW_COLORS, NULL);

    // Original colors:
    // - 0xFF0000
    // - 0xFF7F00
    // - 0xFFFF00
    // - 0x00FF00
    // - 0x0000FF
    // - 0x6600FF
    // - 0x9B00FF
    static const GwColor RAINBOW_COLORS[GW_NUM_RAINBOW_COLORS] = {
        {1.0, 0.0, 0.0, 1.0},
        {1.0, 0.5, 0.0, 1.0},
        {1.0, 1.0, 0.0, 1.0},
        {0.0, 1.0, 0.0, 1.0},
        {0.0, 0.0, 1.0, 1.0},
        {0.4, 0.0, 1.0, 1.0},
        {0.6, 0.0, 1.0, 1.0},
    };

    return &RAINBOW_COLORS[self];
}